import { generate } from "./generate"
import { parse } from "./parse"


const context = {
  _c: function(tag, props, children) {
    return {
      tag,
      props,
      children,
    };
  },
  _v: function() {
    return {};
  },
};

export function compile(template) {
  const ast = parse(template)
  const code = generate(ast)
  return {
    render: function() {
      return new Function(code).call(context)
    }
  }
}
